<?php
namespace app\wechat\traits;
use EasyWeChat\Factory;
/**
 * 小程序服务
 * Class MiniProgram
 * @package app\wechat\traits
 */
trait MiniProgram
{
    protected $config;

    public function __construct()
    {
        $this->config = get_option("wechat_official");
    }

    /**
     * @Notes:根据 jsCode 获取用户 session 信息
     * @User: chenping
     * @email: 375129701@qq.com
     * return [
     *     openid: "oBGVb4xRt2-8t9NxOTZ7ybWzlfCgEefq"
     *     session_key: "ml6CHG1BNlQo3ZjCuIKGfgewFF=="
     * ]
     */
    public function session_user($code)
    {
        if($code)
        {
            $this->config = array_merge($this->config['grograme'],config("official."));
            $app = Factory::miniProgram($this->config);
            return $app->auth->session($code);
        }else{
            return "error:code is not empty";
        }
    }

}